package ihm_clarifiee.Presentation.model_table;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;

public class model_table_detailsprint extends AbstractTableModel {
    private final List<String[]> element = new ArrayList<String[]>();

    private final String[] entetes = {"Histoire","T�che", "Propri�taire"};

    public model_table_detailsprint() {
        super();
    }

    
    public int getRowCount() {
        return element.size();
    }

    public int getColumnCount() {
        return entetes.length;
    }

    public String getColumnName(int columnIndex) {
        return entetes[columnIndex];
    }



    public void add(String [] s) {
        element.add(s);

        fireTableRowsInserted(element.size() -1, element.size() -1);
    }

    public void remove(int rowIndex) {
        element.remove(rowIndex);

        fireTableRowsDeleted(rowIndex, rowIndex);
    }

     public void removeAll()
    {
    if(!element.isEmpty())
    {
     fireTableRowsDeleted(0, element.size() - 1);
     element.clear();}
    }
    public Object getValueAt(int rowIndex, int columnIndex) {
     switch(columnIndex){
            case 0:
                return  element.get(rowIndex)[0];
            case 1:
                return  element.get(rowIndex)[1];
             case 2:
                return  element.get(rowIndex)[2];
            default:
                return null; //Ne devrait jamais arriver
        }
    }
    
    
    public void update(int ligne, String hist, String task, String owner){
        
    	String[] s = {hist, task, owner};
        element.set(ligne, s);
        fireTableDataChanged();
        this.setValueAt(hist, ligne, 0);
        this.setValueAt(task, ligne, 1);
        this.setValueAt(owner, ligne, 2);

        fireTableDataChanged();
        fireTableCellUpdated(ligne, 0);
        fireTableCellUpdated(ligne, 1);
        fireTableCellUpdated(ligne, 2);
    }

}
